﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class touchscreen_buyTicket : System.Web.UI.Page
{
    //Initialize Managers
    MovieManager movieManager;
    PlanningManager planningManager;

    protected void Page_Load(object sender, EventArgs e)
    {
        movieManager = new MovieManager((debioscoopEntities)Session["db"]);
        planningManager = new PlanningManager((debioscoopEntities)Session["db"]);

        //Get movies that play today and bind them to movieList
        List<film> movies = movieManager.getMoviesByDate(DateTime.Today);
        movieList.DataSource = movies;
        movieList.DataBind();

        //Clear session so no leftover order gets in the way
        Session["Bestelling"] = null;

        //Loop trough each item in the movieList 
        foreach (RepeaterItem repeateritem in movieList.Items)
        {
            //Translation of the labels inside the movieList
            Label duration = (Label)repeateritem.FindControl("duration");
            duration.Text = Master.tl.getTranslation("duration") + ":";
            Label times = (Label)repeateritem.FindControl("times");
            times.Text = Master.tl.getTranslation("times") + ":";
            Label genres = (Label)repeateritem.FindControl("genres");
            genres.Text = Master.tl.getTranslation("genres") + ":";

            //Get movieID from hiddenfield and get movie instance
            int movieID = int.Parse(((HiddenField)repeateritem.FindControl("hiddenMovieID")).Value);
            film tempmovie = movieManager.getMovie(movieID);

            //Bind movie times to planningrepeater
            ((Repeater)(repeateritem.FindControl("planningrepeater"))).DataSource = planningManager.getMovieTimes(tempmovie, DateTime.Today);
            ((Repeater)(repeateritem.FindControl("planningrepeater"))).DataBind();
        }

        Master.tl.pageTranslator(buyTicket.Controls);
    }
}